<template>
	<view class="content">

		<view class="box">
			<view class="title">
				<u-icon style="padding: 0;" size="25" name="file-text"></u-icon>
				<view style="margin-left: 15rpx; font-weight:600;"> 用户基础信息</view>
			</view>
			<view class="info">
				<view class="title-info">
					<view>姓&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名:</view>
					<view class="info-right">{{exameInfo.examinerInfo.name}}</view>
				</view>
				<view class="title-info">
					<view>姓&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;别:</view>
					<view class="info-right">{{userInfo.sex}}</view>
				</view>
				<view class="title-info">
					<view>出生年月:</view>
					<view class="info-right">{{userInfo.birs}}</view>

				</view>
				<view class="title-info">
					<view>年&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;龄:</view>
					<view class="info-right">{{userInfo.age}}</view>
				</view>
			</view>
		</view>
		<view v-for="(item,index) in list" v-if="item.inspectionResult=='无异常' || item.inspectionResult=='无'">
		<view class="box-item">
			<view class="box-item-title">
				<u-icon style="padding: 0;" size="25" name="file-text"></u-icon>
				<view style="margin-left: 15rpx; font-weight:600;">{{item.itemName}}</view>
				<view style="display: flex; align-items: center; position: absolute; right:30rpx;">
					<u-icon style="padding: 0;" size="23" color="#55aaff" name="checkmark-circle"></u-icon>
					<view style="margin-left: 15rpx; font-weight:600;"> 正常</view>
				</view>
			</view>
			<view class="box-item-content">
				  {{item.inspectionResult}}
				 <image style="width: 150rpx; height: 150rpx; position: absolute; right: 80rpx;" src="../../static/images2/comm.png"></image>
			</view>
		</view>
</view>

        <view class="box-item2"  v-for="(item,index) in list" v-if="item.inspectionResult!='无异常'">
        	<view class="box-item-title2">
        		<u-icon style="padding: 0;" size="25" name="file-text"></u-icon>
        		<view style="margin-left: 15rpx; font-weight:600;"> {{item.itemName}}</view>
        		<view style="display: flex; align-items: center; position: absolute; right:30rpx;">
        			<u-icon style="padding: 0;" size="23" color="#ffaa00" name="info-circle"></u-icon>
        			<view style="margin-left: 15rpx; font-weight:600;"> 异常</view>
        		</view>
        	</view>
        	<view class="box-item-content3">
        		   {{item.inspectionResult}} 
        	</view>
        	
        </view>

		<!--  <image v-if="img!='null'" :src="img"></image> -->

		<image v-if="img=='null'" src="../../static/images2/empty.png"
			style=" position: absolute; left: 50%; transform: translateX(-50%); width: 400rpx; height: 400rpx;"></image>

	</view>
</template>

<script>
	import order from "@/api/order.js"
	export default {
		data() {
			return {
				img: "",
				exameInfo:{},
				list:[],
				userInfo:{}
			}
		},
	   async onLoad(opstions) {
		       const data =	JSON.parse(decodeURIComponent(opstions.exameInfo))
               this.exameInfo = data
			   console.log(  this.exameInfo,"体检人信息")
			   const dataList =  await order.getBaoGao({orderNo:this.exameInfo.orderNo})
			    this.list = dataList.rows
				console.log(dataList,"数据列表")
                let user = this.parseIDCard(this.exameInfo.examinerInfo.idNumber)
				this.userInfo = user
				console.log(user)
			// this.img = opstions.img
		},
		methods: {
          parseIDCard(idCard) {
                    // 检查身份证长度是否为18位
                    if (idCard.length !== 18) {
                        return "身份证号码无效";
                    }
                
                    // 获取出生日期
                    const birthYear = idCard.substring(6, 10);
                    const birthMonth = idCard.substring(10, 12);
                    const birthDay = idCard.substring(12, 14);
                
                    // 获取性别
                    const genderDigit = parseInt(idCard.charAt(16), 10);
                    const gender = genderDigit % 2 === 1 ? "男" : "女";
                
                    // 计算年龄
                    const today = new Date();
                    const currentYear = today.getFullYear();
                    const currentMonth = today.getMonth() + 1; // JavaScript 的月份是从 0 开始计数的
                    const currentDay = today.getDate();
                
                    let age = currentYear - birthYear;
                    if (
                        (currentMonth < birthMonth) ||
                        (currentMonth === birthMonth && currentDay < birthDay)
                    ) {
                        age--;
                    }
                    return {
                        birs: `${birthYear}年${birthMonth}月${birthDay}日`,
                        sex: gender,
                        age: age
                    };
                }
		} 
	}
</script>

<style scoped>
	.content {
		/* padding-left: 50%; */
		height: 100vh;
		overflow-y: scroll;
		padding: 20rpx;
		/* transform: translateX(50%); */
	}

	.box {
		width: 100%;
		height: 320rpx;
		background-color: white;
		padding: 30rpx;
		line-height: 2;
		border-radius: 20rpx;
	}

	.title {
		display: flex;
	}

	.title-info {
		display: flex;
	}

	.info {
		margin-left: 50rpx;
	}

	.info-right {
		margin-left: 80rpx;
	}

	.box-item {
		width: 100%;
		margin-top: 20rpx;
		
	    position: relative;

	}
	.box-item2{
		 width: 100%;
		 margin-top: 30rpx;
		
		 position: relative;
		 
	}
     .box-item-title2{
		 height: 79rpx;
		 width: 100%;
		 display: flex;
		 align-items: center;
		 border-radius: 20rpx;
		 box-sizing: border-box;
		 padding: 20rpx;
		 background-color:#FFE8C7;
	 }
	.box-item-title {
		height: 79rpx;
		width: 100%;
		display: flex;
		align-items: center;
		border-radius: 20rpx;
		box-sizing: border-box;
		padding: 20rpx;
		background-color:#E1F3FF;
;
	}

	.box-item-content {  
		min-height: 220rpx;
		width: 100%;
		box-sizing: border-box;
		padding: 30rpx;
		background: #EFF7FD;
		font-size: 12px;
		color: #b0b0b0;
		margin-bottom: 20rpx;
	}
	.box-item-content3{
		
		background-color: #FFFBF4;
		min-height: 220rpx;
		width: 100%;
		box-sizing: border-box;
		padding: 30rpx;
	    margin-bottom: 20rpx;
		font-size: 12px;
		color: #b0b0b0;
	}
</style>